package com.ossjk.oa.attendance.service.impl;

import com.ossjk.core.vo.PagePreNextVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.mapper.Condition;
import com.baomidou.mybatisplus.mapper.SqlHelper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.ossjk.oa.attendance.entity.Atdtable;
import com.ossjk.oa.attendance.mapper.AtdtableMapper;
import com.ossjk.oa.attendance.service.IAtdtableService;
import com.ossjk.oa.attendance.vo.AtdtableVo;

import java.util.List;

/**
 * 服务实现类
 * 
 * @Author Datou
 * @Version 1.0, 2020-05-23
 * @See
 * @Since com.ossjk.oa.attendance.service.impl
 * @Description: TODO
 */
@Service
public class AtdtableServiceImpl extends ServiceImpl<AtdtableMapper, Atdtable> implements IAtdtableService {

	@Autowired
	private IAtdtableService iAtdtableService;

	@Override
	public boolean geneAtdTable(Atdtable atdtable) {
		// 删除已有报表
		Wrapper wrapper = Condition.create().eq("eid", atdtable.getEid()).eq("did", atdtable.getDid());
		iAtdtableService.delete(wrapper);
		return iAtdtableService.insert(atdtable);
	}

	@Override
	public Page selectVoPage(Page page, Wrapper wrapper) {
		SqlHelper.fillWrapper(page, wrapper);
		page.setRecords(baseMapper.selectVoPage(page, wrapper));
		return page;
	}

	@Override
	public AtdtableVo selectVo(Wrapper wrapper) {
		// TODO Auto-generated method stub
		return baseMapper.selectVo(wrapper);
	}

	@Override
	public List selectKQTable(Wrapper wrapper) {
		return baseMapper.selectKQTable(wrapper);
	}
	@Override
	public PagePreNextVo selectPreNext(String midMth) {

		PagePreNextVo vo = new PagePreNextVo();

		String[] strs = midMth.split("-");

		Integer mth =Integer.parseInt(strs[0])*100 +Integer.parseInt(strs[1]);
		System.out.println(mth);

		Integer tmpX =this.baseMapper.selectPreMth(mth);
		//202005   to 2020-05
		vo.setPre(tmpX==null?" ":(tmpX+"").substring(0, 4)+ "-"+ (tmpX+"").substring( 4)   );
		tmpX =this.baseMapper.selectNextMth(mth);
		vo.setNext(tmpX==null?" ":(tmpX+"").substring(0, 4)+ "-"+ (tmpX+"").substring( 4));
		vo.setCurrent(  (midMth+"").substring(0, 4)+ "-"+ (midMth+"").substring( 4));

		return vo;
	}


}
